package com.qf.controller;


import com.github.pagehelper.PageInfo;
import com.qf.dto.R;
import com.qf.pojo.Author;
import com.qf.service.AuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/author")
public class AuthorController {

    private AuthorService authorService;

    @Autowired
    public void setAuthorService(AuthorService authorService) {
        this.authorService = authorService;
    }

    @PostMapping("/newauthor")
    public R addAuthor(@RequestBody Author author){

        authorService.addAuthor(author);

        return R.setOk(null);

    }

    @GetMapping("/authors/{pageNum}/{pageSize}")
    public R getAllAuthor(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize){
        PageInfo<Author> pageInfo = authorService.getAllAuthor(pageNum,pageSize);
        return R.setOk(pageInfo);
    }

}
